package com.zenithmind.library.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 图书状态枚举
 * 
 * @author ZenithMind
 * @since 2024-06-14
 */
@Getter
@AllArgsConstructor
public enum BookStatus {
    
    /**
     * 可借阅
     */
    AVAILABLE(0, "可借阅"),
    
    /**
     * 已借出
     */
    BORROWED(1, "已借出"),
    
    /**
     * 已预约
     */
    RESERVED(2, "已预约"),
    
    /**
     * 维护中
     */
    MAINTENANCE(3, "维护中"),
    
    /**
     * 已损坏
     */
    DAMAGED(4, "已损坏"),
    
    /**
     * 已丢失
     */
    LOST(5, "已丢失"),
    
    /**
     * 已下架
     */
    WITHDRAWN(6, "已下架");
    
    private final Integer code;
    private final String description;
    
    /**
     * 根据代码获取枚举
     */
    public static BookStatus getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (BookStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
    
    /**
     * 判断是否可借阅
     */
    public boolean isAvailable() {
        return this == AVAILABLE;
    }
    
    /**
     * 判断是否已借出
     */
    public boolean isBorrowed() {
        return this == BORROWED;
    }
    
    /**
     * 判断是否已预约
     */
    public boolean isReserved() {
        return this == RESERVED;
    }
}
